﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion


#region Usings

using System;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Surface.Presentation;
using ScrumTable.BL.DM.DataManagement;
using ScrumTable.UI.View.Controls;
using ScrumTable.UI.View.Extension;
using ScrumTable.UI.ViewModel;

#endregion

namespace ScrumTable.UI.View.WinTouch.UserControls.Menu
{
 

    /// <summary>
    /// Interaction logic for ContextMenu.xaml
    /// </summary>
    public partial class DropStateControl 
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

 
        
        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        public Array States { get; set; }
        public Type ViewModelType { get; private set; }
        
        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

         
        public DropStateControl()
        {
            DataContext = this;
            InitializeComponent();
        }


        public DropStateControl(object viewModel)
        {
            DataContext = this;
            InitializeComponent();
            StateText.Content = viewModel;
        }
 
        #endregion
        
    }


    #region DropStateControlDrop
    public class DropStateControlDrop : UserControl, IDropUserControl
    {
        private Func<object, ScrumState, CanDropResult> _canDrop;
        private ScrumState _state;
        private IScrumItemViewModel<DomainBase> _viewModel;

        public DropStateControlDrop(Func<object, ScrumState, CanDropResult> canDrop, ScrumState state, IScrumItemViewModel<DomainBase> viewModel)
        {
            _state = state;
            _canDrop = canDrop;
            SurfaceDragDrop.AddDropHandler(this, OnDropHandler);
            Content = new DropStateControl(state);
            AllowDrop = true;
            _viewModel = viewModel;
        }

        private void OnDropHandler(object sender, SurfaceDragDropEventArgs args)
        {
            if (CanDrop(args.Cursor.Data) == CanDropResult.CanDrop)
            {
                _viewModel.State = _state;
            }
        }

        public FrameworkElement GetRootControl
        {
            get { return ((DropStateControl)Content).DropRoot; }
        }

        public bool ShowIconWithbackground
        {
            get { return false; }
        }

        public CanDropResult CanDrop(object objectToDrop)
        {
            return _canDrop(objectToDrop, _state);
        }
    }
    #endregion
}
